package errorHandle

import (
	"errors"
	"fmt"
	"strings"
)

func ErrorHandle() {
	// 使用defer + recover处理异常
	defer func() {
		// err := recover()
		if err := recover(); err != nil {
			fmt.Println("err = ", err)
		}
	}()
	var n1 int = 10
	var n2 int = 0
	var n3 = n1 / n2
	fmt.Println("n3 = ", n3)
}

func ErrorHandle2(name string) error {
	if strings.HasSuffix(name, ".ini") {
		return nil
	}
	return errors.New("传入文件后缀有误")
}
